//
//  JFAlertController.h
//  alertViewClass
//
//  Created by ranjingfu on 15/12/21.
//  Copyright © 2015年 ranjingfu. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
@class UITextField;

/**
 *  JFAlertActionStyle    对应的按钮样式
 */
typedef NS_ENUM(NSInteger, JFAlertActionStyle) {
    /**
     *  默认按钮样式
     */
    JFAlertActionStyleDefault = 0,
    /**
     *  取消按钮样式
     */
    JFAlertActionStyleCancel,
    /**
     *
     */
    JFAlertActionStyleDestructive
};

/**
 *   JFAlertControllerStyle   controllerView的展现形式 有alert和actionSheet形式
 */
typedef NS_ENUM(NSInteger, JFAlertControllerStyle) {
    /**
     *   显示actionSheet样式的模态页面
     */
    JFAlertControllerStyleActionSheet = 0,
    /**
     *  显示alertView模式的模态页面
     */
    JFAlertControllerStyleAlert
};


@interface JFAlertAction : NSObject
@property (strong, nonatomic, readonly) NSString *title;
@property (nonatomic, readonly) JFAlertActionStyle style;
@property (nonatomic, assign) BOOL enabled;

+ (instancetype)actionWithTitle:(NSString *)title style:(JFAlertActionStyle)style handler:(void (^)(JFAlertAction* action))handler;
@end


@interface JFAlertController : NSObject
@property (nonatomic, readonly) NSArray *actions;
@property (nonatomic, strong) JFAlertAction *preferredAction;
@property (nonatomic, readonly) NSArray *textFields;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *message;
@property (nonatomic, readonly) JFAlertControllerStyle preferredStyle;



/**
 *  生成JFAlertController的类方法，如果需要响应按钮，请使用addAction 添加按钮（show 之前调用）
 *
 *  @param title          标题
 *  @param message        内容
 *  @param preferredStyle style 见JFAlertControllerStyle
 *
 *  @return <#return value description#>
 */
+ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message preferredStyle:(JFAlertControllerStyle)preferredStyle;


/**
 *  为Alert只有小于等于两个按钮时单独设计的类方法 返回一个JFAlertControllerStyleAlert 类型的alertView
 *
 *  @param title        标题
 *  @param message      消息内容
 *  @param cancelAction 取消action
 *  @param ensureAction 确认action
 *
 *  @return JFAlertController 实例
 */
+ (instancetype)alertControllerWithTitle:(NSString *)title message:(NSString *)message cancelAction:(JFAlertAction*)cancelAction ensureAction:(JFAlertAction*)ensureAction;
/**
 *  添加按钮及对应的响应方法（必须在show之前调用）
 *
 *  @param action 按钮动作
 */
- (void)addAction:(JFAlertAction *)action;

/**
 *  添加按钮及对应的响应方法（必须在show之前调用）
 *
 *  @param arrayActions  JFAlertAction 数组
 */
- (void)addActions:(NSArray*)arrayActions;
/**
 *  iOS8以下此方法什么都不做，iOS8极以上参见UIAlertController的addTextFieldWithConfigurationHandler
 *
 *  @param configurationHandler textField的各种属性配置
 */

- (void)addTextFieldWithConfigurationHandler:(void (^)(UITextField *textField))configurationHandler;

/**
 *  显示alert，actionSheet或者alertController
 *
 *  @param viewController 显示的viewController
 */
- (void)showInViewController:(UIViewController*)viewController;

/**
 *  显示alert，actionSheet或者alertController
 *
 *  @param viewController 显示的viewController
 *  @param animate        是否需要动画
 */
- (void)showInViewController:(UIViewController*)viewController animated:(BOOL)animate;

/**
 *  显示alert，actionSheet或者alertController
 *
 *  @param viewController 显示的viewController
 *  @param animate        是否需要动画
 *  @param completed      显示完成之后调用
 */
- (void)showInViewController:(UIViewController*)viewController animated:(BOOL)animate compeleted:(void (^)())completed;

@end
